//
//  JMViewController.m
//  JMLibrary
//
//  Created by zhengxianda on 07/20/2018.
//  Copyright (c) 2018 zhengxianda. All rights reserved.
//

#import "JMViewController.h"

#import <JMLibrary/JMShare.h>

@interface JMViewController ()

@property(nonatomic, strong) JMShareMessageObject * textObject;
@property(nonatomic, strong) JMShareMessageObject * imageObject;
@property(nonatomic, strong) JMShareMessageObject * webObject;
@property(nonatomic, strong) JMShareMessageObject * musicObject;

@property(nonatomic, strong) JMShareRequestHandler handler;


@end

@implementation JMViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIImage * image = [UIImage imageNamed:@"avatar"];
    NSData * thumbImageData = UIImageJPEGRepresentation(image,0.1);
    NSData * shareImageData = UIImageJPEGRepresentation(image,1);
    
    NSURL * webPageURL = [NSURL URLWithString:@"http://www.baidu.com"];
    
    NSURL * musicDataURL = [NSURL URLWithString:@"http://www.ytmp3.cn/down/49800.mp3"];
    NSURL * musicPageURL = [NSURL URLWithString:@"http://www.ytmp3.cn/p/49800.html"];
    
    NSLog(@"\n\
          -*-thumbImageData: %d;\n\
          -*-shareImageData: %d;\n",
          (int)(thumbImageData.length/1024), (int)(shareImageData.length/1024));
    
    self.textObject = [JMShareMessageObject objecWithText:@"文本内容"];
    self.imageObject = [JMShareMessageObject objecWithTitle:@"图片标题"
                                               descriptions:@"图片描述"
                                                 thumbImage:thumbImageData
                                                 shareImage:shareImageData];
    self.webObject = [JMShareMessageObject objecWithTitle:@"网页标题"
                                             descriptions:@"网页描述"
                                               thumbImage:thumbImageData
                                               webPageURL:webPageURL];
    self.musicObject = [JMShareMessageObject objecWithTitle:@"音乐标题"
                                               descriptions:@"音乐描述"
                                                 thumbImage:thumbImageData
                                               musicDataURL:musicDataURL
                                               musicPageURL:musicPageURL];
    
    self.handler = ^(NSError *error) {
        if (error) {
            NSLog(@"Fial: %@ - %ld", error.userInfo[@"msg"], error.code);
        }else{
            NSLog(@"Success");
        }
    };
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)weiboButtonTapped:(id)sender {
    [JMShare shareToChannel:JMShareChannelSinaWeibo messageObject:self.musicObject handler:self.handler];
}
- (IBAction)wechatButtonTapped:(id)sender {
    [JMShare shareToChannel:JMShareChannelWeChatMessage messageObject:self.musicObject handler:self.handler];
}
- (IBAction)timelineButtonTapped:(id)sender {
    [JMShare shareToChannel:JMShareChannelWeChatTimeline messageObject:self.musicObject handler:self.handler];
}
- (IBAction)qqButtonTapped:(id)sender {
    [JMShare shareToChannel:JMShareChannelTencentQQ messageObject:self.musicObject handler:self.handler];
}
- (IBAction)zoneButtonTapped:(id)sender {
    [JMShare shareToChannel:JMShareChannelTencentQQZone messageObject:self.musicObject handler:self.handler];
}

@end
